<template>
  <div style="sample-modal">
      <a-steps direction="vertical" :current="-1">
    <a-step title="输入艺术家">
     <div class="artist-input step-template" slot="description">
         <div>  
             <a-input-search placeholder="请输入搜索关键字" style="width: 200px;margin-left:10px" @search="onSearch" />
         </div>
         <div class="artist-box">
             <a-avatar :size="40" icon="user" />
             <span style="margin-left:20px">马丁帕尔</span>
         </div>
    </div>
    </a-step>
    <a-step title="输入作品集名称">
     <div class="step-template" slot="description">
          <a-input placeholder="sample" style="width: 170px"/>
    </div>
    </a-step>
    <a-step title="上传封面">
     <div class="step-template" slot="description">
         <a-upload
    name="avatar"
    list-type="picture-card"
    class="avatar-uploader"
    :show-upload-list="false"
    action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
    :before-upload="beforeUpload"
    @change="handleChange"
  >
    <img v-if="imageUrl" :src="imageUrl" alt="avatar" />
    <div v-else>
      <a-icon :type="loading ? 'loading' : 'plus'" />
      <div class="ant-upload-text">
        Upload
      </div>
    </div>
  </a-upload>
    </div>
    </a-step>
    <a-step title="输入作品简介">
     <div class="step-template"  style="width:50%" slot="description">
        <a-textarea placeholder="Basic usage" :rows="4" />
    </div>
    </a-step>
    <a-step  title="上传图片">
     <div class="step-template" slot="description">
        <a-upload
      action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
      list-type="picture-card"
      :file-list="fileList"
      @preview="handlePreview"
      @change="handleChange"
    >
      <div v-if="fileList.length < 18">
        <a-icon type="plus" />
        <div class="ant-upload-text">
          Upload
        </div>
      </div>
    </a-upload>
    </div>
    </a-step>
  </a-steps>
  </div>
</template>

<script>
function getBase64(img, callback) {
  const reader = new FileReader();
  reader.addEventListener('load', () => callback(reader.result));
  reader.readAsDataURL(img);
}
export default {
    data () {
        return {
            loading: false,
            imageUrl:"",
             fileList: [
        {
          uid: '-1',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
        },
        {
          uid: '-2',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
        },
        {
          uid: '-3',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
        },
        {
          uid: '-4',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
        },
        {
          uid: '-5',
          name: 'image.png',
          status: 'error',
        },
      ],
        }
    },
    methods:{
        handleChange(info) {
      if (info.file.status === 'uploading') {
        this.loading = true;
        return;
      }
      if (info.file.status === 'done') {
        // Get this url from response in real world.
        getBase64(info.file.originFileObj, imageUrl => {
          this.imageUrl = imageUrl;
          this.loading = false;
        });
      }
    },
    beforeUpload(file) {
      const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png';
      if (!isJpgOrPng) {
        this.$message.error('You can only upload JPG file!');
      }
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isLt2M) {
        this.$message.error('Image must smaller than 2MB!');
      }
      return isJpgOrPng && isLt2M;
    },
    }
}
</script>

<style>
.artist-input{
    display: flex;
    align-items: center;
}
.artist-box{
    display: flex;
    justify-content: space-around;
    background-color: #d8d8d862;
    align-items: center;
    height: 63px;
    padding: 0 20px;
    margin-left: 30px;
}
.avatar-uploader > .ant-upload {
  width: 128px;
  height: 128px;
}
.ant-upload-select-picture-card i {
  font-size: 32px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}
.step-template{
    margin: 15px ;
}
.sample-modal{
    height: 500px;
    overflow: scroll;
}
</style>